package com.ybl.store.backend.controller;

import com.ybl.store.backend.dto.req.ManagerSaveReqDTO;
import com.ybl.store.backend.dto.req.ManagerUpdateReqDTO;
import com.ybl.store.backend.dto.resp.ListRespDTO;
import com.ybl.store.backend.dto.resp.ManagerPageRespDTO;
import com.ybl.store.backend.dto.resp.ManagerRealNameRespDTO;
import com.ybl.store.backend.dto.resp.ManagerSaveRespDTO;
import com.ybl.store.backend.service.impl.ManagerServiceImpl;
import com.ybl.store.common.convention.result.Result;
import com.ybl.store.common.convention.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 店长控制层
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/manager")
public class ManagerController {

    private final ManagerServiceImpl managerService;

    /**
     * 新增店长
     */
    @PostMapping
    public Result<ManagerSaveRespDTO> saveManager(@RequestBody ManagerSaveReqDTO requestParam) {
        return Results.success(managerService.saveManager(requestParam));
    }

    /**
     * 删除店长
     */
    @DeleteMapping
    public Result<Void> deleteManagerById(@RequestParam("id") Long id) {
        managerService.deleteManagerById(id);
        return Results.success();
    }

    /**
     * 修改店长
     */
    @PutMapping
    public Result<Void> updateManager(@RequestBody ManagerUpdateReqDTO requestParam) {
        managerService.updateManager(requestParam);
        return Results.success();
    }

    /**
     * 分页查询店长
     */
    @GetMapping("/page")
    public Result<ManagerPageRespDTO> pageManager(
            @RequestParam("pn") Integer pn,
            @RequestParam("ps") Integer ps,
            @RequestParam(required = false) Long storeId,
            @RequestParam(required = false) String realName)
    {
        return Results.success(managerService.pageManager(pn, ps, storeId, realName));
    }

    /**
     * 查询店长名列表
     */
    @GetMapping("/realName/list")
    public Result<ListRespDTO<ManagerRealNameRespDTO>> listManagerRealName() {
        return Results.success(managerService.listManagerRealName());
    }
}
